<template>
	<view>
		<!-- 物流信息  -->
		<view class="list-box">
			<view class="setTitle">
				<view class="address-list">
					<view class="address-left">收货信息</view>
					<view class="address-right">
						<image class="address-right-image" src="/static/images/address.png"></image>
						<view class="right-txt" v-if="logisticsDetails.receiving_phone">
							<view>{{logisticsDetails.receiving_name}}({{logisticsDetails.receiving_phone}})</view>
							<view>{{logisticsDetails.receiving_address}}</view>
						</view>
					</view>
				</view>
				<view class="address-list">
					<view class="address-left">物流信息</view>
					<view class="address-right">
						<view class="address-right-image"></view>
						<view class="right-txt">
							<view>订单编号：{{order_no}}</view>
							<view>物流公司：{{logisticsDetails.express_name}}</view>
							<view>快递单号：{{logisticsDetails.nu}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="logistics-lists">
				<view class="logistics-list" v-for="(item, index) in logisticsDetails.data" :key="index">
					<view class="logistics-middle">
						<view class="logistics-round"></view>
						<view class="logistics-line"></view>
					</view>
					<view class="logistics-right">
						<view class="logistics-left">{{item.ftime}}</view>
						<view>{{item.context}}</view>
					</view>
				</view>
				<view class="logistics-tips" v-if="!logisticsDetails||!logisticsDetails.data||!logisticsDetails.data.length">暂无物流信息</view>
			</view>
		</view>

		<!-- 推荐商品 -->
		<view v-if="recommendList.length>0" class="home-recommend">
			<view class="home-nomoral-title-box">
				<view class="home-nomoral-title">推荐商品</view>
			</view>
			<view class="home-recommend-list-box">
				<view class="home-recommend-list" v-for="(item, index) in recommendList" :key="index" @tap.stop="details" :data-id="item.goods_id">
					<view class="home-recommend-list-img">
						<view v-if="item.goods_num<=0" class="goods-sell-empty">已售空</view>
						<image mode="aspectFit" lazy-load="true" :src="item.goods_image"></image>
					</view>
					<view class="home-nomoral-list-name home-recommend-padding">{{item.goods_name}}</view>
					<view v-if="item.promotion_status==1" class="home-recommend-price">￥{{item.act_price}}</view>
					<block v-else>
						<view class="home-recommend-price" v-if="showPlusPrice(item)">
							<text class="plus-price-color">￥{{item.plus_price}}</text>
							<text class="plus-price-icon">PLUS</text>
						</view>
						<view class="home-recommend-price" v-if="showVipPrice(item)">
							<text class="price-color">￥{{item.shop_mem_price}}</text>
							<text class="vip-price-icon">VIP</text>
						</view>
						<view class="home-recommend-price" v-if="showOnlinePrice(item)">￥{{item.online_price}}</view>
					</block>
				</view>
			</view>
		</view>
		<view class="loading">
			<block v-if="isLoading">
				<image src="https://mall.xzthealth.com/loading2.gif"></image>
				<text>加载中</text>
			</block>
			<text v-else-if="canLoad">下拉加载更多</text>
			<text v-else-if="!canLoad&&(!recommendList||!recommendList.length)">暂无推荐商品</text>
			<text v-else>已加载全部</text>
		</view>
	</view>
</template>

<script>
	// pages/logistics/logistics.js
	var app = getApp().globalData;

	export default {
		data() {
			return {
				recommendList: [],//推荐商品列表
				recommendPage: 0,//推荐商品分页
				canLoad: true,//推荐商品是否可以加载
				isLoading: false, //推荐商品是否正在加载
				logisticsDetails: "",
				order_no: "",
				store_id: '',
				express_order_id:'', //物流订单ID
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		async onLoad(options) {
			await this.$onLaunched;
			this.order_no = options.order_no;
			this.store_id = options.store_id;
			this.express_order_id = options.express_order_id

			console.log(this.express_order_id   , 'express_order_idexpress_order_idexpress_order_id')
			this.getLogistics();
		},

		methods: {
			// 展示plus会员价条件
			showPlusPrice(item) {
				return getApp().globalData.showPlusPrice(item)
			},
			
			// 展示会员价条件
			showVipPrice(item) {
				return getApp().globalData.showVipPrice(item)
			},
			
			// 展示普通价格
			showOnlinePrice(item) {
				return getApp().globalData.showOnlinePrice(item)
			},
			//获取物流详情
			getLogistics: function() {
				var that = this;
				getApp().globalData.sendRequest({
					url: '/Order/getOrderExpress',
					type: "post",
					data: {
						order_no: this.order_no,
						express_order_id:this.express_order_id 
					},
					success: function(res) {
						if (res.status == 1) {
							that.setData({
								logisticsDetails: res.data
							});
						}
					}
				});
			},
			//商品详情
			details: function(e) {
				uni.navigateTo({
					url: '/pages/product/details/details?id=' + e.currentTarget.dataset.id
				});
			},
			//商家推荐商品
			getRecommend: function() {
				var that = this;

				if (this.canLoad) {
					this.setData({
						canLoad: false,
						isLoading: true
					});
					var recommendPage = parseInt(this.recommendPage) + 1;
					getApp().globalData.sendRequest({
						url: '/Goods/getSellGoods_v1',
						type: "post",
						needSign: false,
						data: {
							page: recommendPage,
							store_id: this.store_id,
						},
						showLoading: false,
						success: function(res) {
							if (res.status == 1) {
								var recommendList = that.recommendList;

								if (recommendPage != 1) {
									//第一页
									recommendList.push.apply(recommendList, res.info);
								} else {
									recommendList = res.info;
								}

								var canLoad = true;

								if (res.info.length < res.limit || !res.info.length) {
									canLoad = false;
								}

								that.setData({
									recommendList: recommendList,
									canLoad: canLoad,
									isLoading: false,
									recommendPage: recommendPage
								});
							} else {
								that.setData({
									recommendList: [],
									canLoad: false,
									isLoading: false
								});
							}
						}
					});
				}
			}
		}
	};
</script>
<style>
	@import "./logistics.css";
</style>
